/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package persistencia;

import persistencia.DAO;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;


/**
 *
 * @author Marcelo
 */
public class OutputDAO extends DAO {

    private FileOutputStream fos;
    private ObjectOutputStream out;
    private File file;
    private void open() throws FileNotFoundException, IOException {
        fos = new FileOutputStream(PATH);       
        out = new ObjectOutputStream(fos);
    }

    private void close() throws IOException {
        if (out != null) {
            out.close();
        }
    }

    @Override
    public void write(Object obj) throws IOException {
        System.out.println("Class write: " + obj.getClass().toString());
        open();
        if (out != null) {
            out.writeObject(obj);
            close();
        }
    }
    
}
